package com.lagou.edu.service.impl;

import com.lagou.edu.dao.ResumeDao;
import com.lagou.edu.dto.ResumeDto;
import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.IResumeService;
import com.lagou.edu.vo.ResumeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
public class ResumeServiceImpl implements IResumeService {

    @Autowired
    private ResumeDao resumeDao;
    @Override
    public List<Resume> queryAll() {
        return resumeDao.findAll();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResumeVo addResume(ResumeDto dto) throws Exception {
        Resume resume=dto.toEntity();
        resumeDao.save(resume);
        ResumeVo vo=resume.toVo();
        return vo;

    }

    @Override
    public void deleteResume(Long id) {
       resumeDao.deleteById(id);
    }

    @Override
    public ResumeVo get(Long id) {
        Optional<Resume> optional = resumeDao.findById(id);
        Resume resume = optional.get();
        ResumeVo resumeVo = resume.toVo();
        return resumeVo;
    }
}
